﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using Memcached;
using System.Configuration;
using System.IO;


public partial class gold_eGoldChart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string strDate = System.DateTime.Now.Date.ToString("yyyyMMdd");
        //"E://公司项目//[CMS]//CMS//CMS//gold//dataimg/"
        //string strIMGPath = ConfigurationManager.AppSettings["eGold_imgpath"];
        //string Path = strIMGPath + strDate;
        //if (!System.IO.File.Exists(Path))
        //{
        //    DirectoryInfo d = Directory.CreateDirectory(Path);
        //}
        //如果没有当天的文件夹，则生成    
        string strFilePath = ConfigurationManager.AppSettings["eGold_filepath"];
        string File = strFilePath + strDate;
        eGoldFunction ef = new eGoldFunction();
        ef.IsFile(File);

      
        Series series_down = new Series("Column");
        Series series_up = new Series("Column");
        series_down.ChartType = SeriesChartType.Column;
        series_down.BorderWidth = 3;
        series_down.IsVisibleInLegend = true;

       
        //series_down.IsValueShownAsLabel = true;
        series_down["PointWidth"] = "0.8";
        series_down.Color = System.Drawing.Color.FromArgb(255, 32, 32);// System.Drawing.Color.Green;   //柱状颜色
        Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
        Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; //仅不显示x轴方向的网格线
        Memcached.JSON c = new JSON();
        string strIP = ConfigurationManager.AppSettings["Stock_Info"];
        string strKey = "EMONEY_DATA_GOLD_TOP_GROUP_HY_DOWN";   //EMONEY_DATA_1.0_TOP_GROUP_HY_DOWN
        string strJson = c.GetJsonByKeyIP(strKey, strIP);

        List<BKList> data;
        data= (List<BKList>)(Newtonsoft.Json.JsonConvert.DeserializeObject<List<BKList>>(strJson));

        int num = 0;
        foreach (BKList d in data)
        {
            if (num <= 9)
            {
                if (Convert.ToDecimal(d.J) > 0)
                {
                    series_down.Points.AddXY(d.N, d.J);
                    series_down.Points[num].IsValueShownAsLabel = true;
                    num++;
                }
                else
                {
                    series_down.Points.AddXY(" ", "");
                    series_down.Points[num].IsValueShownAsLabel = false;
                    num++;
                }
            }
        }

        Chart1.Series.Add(series_down);
        Chart1.ImageLocation = "data/" + strDate + "/bk_down.png";
        Chart1.ImageStorageMode = ImageStorageMode.UseImageLocation;
        Chart1.ImageType = ChartImageType.Png; //保存格式



        series_up.ChartType = SeriesChartType.Column;
        series_up.BorderWidth = 3;
        series_up.IsVisibleInLegend = true;
        series_up.IsValueShownAsLabel = true;
        series_up["PointWidth"] = "0.8";
        series_up.Color = System.Drawing.Color.FromArgb(15, 113, 62);// System.Drawing.Color.Green;   //柱状颜色
        Chart2.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
        Chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false; //仅不显示x轴方向的网格线
        Memcached.JSON c1 = new JSON();
        string strIP1 = ConfigurationManager.AppSettings["Stock_Info"];
        string strKey1 = "EMONEY_DATA_GOLD_TOP_GROUP_HY_UP";
        string strJson1 = c.GetJsonByKeyIP(strKey1, strIP1);

        List<BKList> data1;
        data1 = (List<BKList>)(Newtonsoft.Json.JsonConvert.DeserializeObject<List<BKList>>(strJson1));

        num = 0;
        foreach (BKList d in data1)
        {
            if (num <= 9)
            {
                if (0 - Convert.ToDecimal(d.J) > 0)
                {
                    series_up.Points.AddXY(d.N, 0 - double.Parse(d.J));
                    series_up.Points[num].IsValueShownAsLabel = true;
                    num++;
                }
                else
                {
                    series_up.Points.AddXY(" ", "");
                    series_up.Points[num].IsValueShownAsLabel = false;
                    num++;
                }
                
            }
        }

        Chart2.Series.Add(series_up);
        //Chart2.ImageLocation = "../temppic/bk_up.png";
        Chart2.ImageLocation = "data/" + strDate+"/bk_up.png";
        Chart2.ImageStorageMode = ImageStorageMode.UseImageLocation;
        Chart2.ImageType = ChartImageType.Png; //保存格式


       


    }
    protected void saveimg_Click(object sender, EventArgs e)
    {

     
        //文件转byte
        string strDate = System.DateTime.Now.Date.ToString("yyyyMMdd");
       
        string strFilePath = ConfigurationManager.AppSettings["eGold_filepath"];

        string strIMGPath = ConfigurationManager.AppSettings["eGold_imgpath"];
        string strIMGUrlPath = ConfigurationManager.AppSettings["eGold_imgurlpath"];
        //是否存在文件夹
        eGoldFunction ef = new eGoldFunction();
        ef.IsFile(strFilePath + strDate + "/em_bkzj");

        string msg = "''";
        FileStream stream = new FileStream(strFilePath + strDate + "/bk_up.png", FileMode.Open);
        byte[] bkup = new byte[stream.Length];
        stream.Read(bkup, 0, (int)stream.Length);
        //本地
        FileStream streamlocal = new FileStream(strFilePath + strDate + "/em_bkzj/bk_up.png", FileMode.OpenOrCreate, FileAccess.ReadWrite);
        streamlocal.Write(bkup, 0, bkup.Length);
        streamlocal.Close();

        FileStream stream1 = new FileStream(strFilePath + strDate + "/bk_down.png", FileMode.Open);
        byte[] bkdown = new byte[stream1.Length];
        stream1.Read(bkdown, 0, (int)stream1.Length);
        //本地
        FileStream streamlocal1 = new FileStream(strFilePath + strDate + "/em_bkzj/bk_down.png", FileMode.OpenOrCreate, FileAccess.ReadWrite);
        streamlocal1.Write(bkdown, 0, bkdown.Length);
        streamlocal1.Close();

        stream1.Close();
        stream.Close();
        Deliver.AsynchronousClient.StartTranCommand(bkup, strIMGPath + strDate + "/bk_up.png", out msg);
        Deliver.AsynchronousClient.StartTranCommand(bkdown, strIMGPath + strDate + "/bk_down.png", out msg);

        //存本地
        //FileStream fs = new FileStream(strImgLocalPath + strDate + "/" + pagename + "/" + strid + ".jpg", FileMode.OpenOrCreate, FileAccess.ReadWrite);
        //fs.Write(file, 0, file.Length);
        //fs.Close();
    }
   
}